
Partial Class Budget_Codes
    Inherits System.Web.UI.Page

    Protected Property ServiceCodeGridViewSortDirection() As String
        Get
            If ViewState("ServiceCodeSortDirection") Is Nothing Then
                ViewState("ServiceCodeSortDirection") = SortDirection.Ascending
            End If
            Return CType(ViewState("ServiceCodeSortDirection"), SortDirection)
        End Get
        Set(ByVal value As String)
            ViewState("ServiceCodeSortDirection") = value
        End Set
    End Property

    Protected Property ItemCodeGridViewSortDirection() As String
        Get
            If ViewState("ItemCodeSortDirection") Is Nothing Then
                ViewState("ItemCodeSortDirection") = SortDirection.Ascending
            End If
            Return CType(ViewState("ItemCodeSortDirection"), SortDirection)
        End Get
        Set(ByVal value As String)
            ViewState("ItemCodeSortDirection") = value
        End Set
    End Property

    Protected Property ServiceCodeGridViewSortExpression() As String
        Get
            If ViewState("ServiceCodeSortExpression") Is Nothing Then
                ViewState("ServiceCodeSortExpression") = "ServiceCode"
            End If
            Return ViewState("ServiceCodeSortExpression")
        End Get
        Set(ByVal value As String)
            ViewState("ServiceCodeSortExpression") = value
        End Set
    End Property

    Protected Property ItemCodeGridViewSortExpression() As String
        Get
            If ViewState("ItemCodeSortExpression") Is Nothing Then
                ViewState("ItemCodeSortExpression") = "ItemCode"
            End If
            Return ViewState("ItemCodeSortExpression")
        End Get
        Set(ByVal value As String)
            ViewState("ItemCodeSortExpression") = value
        End Set
    End Property

    Protected Sub Page_Load(ByVal sender As Object, _
                            ByVal e As System.EventArgs) _
                            Handles Me.Load

        SetupJAvascript()
        If Not Page.IsPostBack Then

            Me.BindServiceCodesGrid("ServiceCode")
            Me.BindItemCodesGrid("ItemCode")

        End If

    End Sub


    Private Sub SetupJavaScript()
        EntityController.JavaScriptSetFixedHeight(0)
        EntityController.JavaScriptAddChildDiv(Me.mainDiv.ClientID, 50)
    End Sub
    Protected Sub BindServiceCodesGrid(ByVal sortExpression As String)

        If ServiceCodeGridViewSortDirection = SortDirection.Descending Then
            Me.ServiceCodesGridView.DataSource = Cdm.DataCore.LookupTables.LuServiceCode.ListBySort(sortExpression, False)
        Else
            Me.ServiceCodesGridView.DataSource = Cdm.DataCore.LookupTables.LuServiceCode.ListBySort(sortExpression, True)
        End If
        Me.ServiceCodesGridView.DataBind()

    End Sub

    Protected Sub BindItemCodesGrid(ByVal sortExpression As String)

        If ItemCodeGridViewSortDirection = SortDirection.Descending Then
            Me.ItemCodesGridView.DataSource = Cdm.DataCore.LookupTables.LuItemCode.ListBySort(sortExpression, False)
        Else
            Me.ItemCodesGridView.DataSource = Cdm.DataCore.LookupTables.LuItemCode.ListBySort(sortExpression, True)
        End If

        Me.ItemCodesGridView.DataBind()

    End Sub

    Protected Sub ItemCodesGridView_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles ItemCodesGridView.Sorting

        If ItemCodeGridViewSortDirection = SortDirection.Ascending Then
            ItemCodeGridViewSortDirection = SortDirection.Descending
            Me.BindItemCodesGrid(e.SortExpression)
        Else
            ItemCodeGridViewSortDirection = SortDirection.Ascending
            Me.BindItemCodesGrid(e.SortExpression)
        End If

    End Sub

    Protected Sub ServiceCodesGridView_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles ServiceCodesGridView.Sorting

        If ServiceCodeGridViewSortDirection = SortDirection.Ascending Then
            ServiceCodeGridViewSortDirection = SortDirection.Descending
            Me.BindServiceCodesGrid(e.SortExpression)
        Else
            ServiceCodeGridViewSortDirection = SortDirection.Ascending
            Me.BindServiceCodesGrid(e.SortExpression)
        End If

    End Sub
End Class
